** Replication files for "Ministerial Autonomy, Paliamentary Scrutiny and Government reform Output in Parliamentary Democracies
** Authors: Hanna Bäck, Wolfgang C. Müller, Mariyana Angelova, Daniel Strobl

** This file replicates table 1, table 2 and figures 4, 6, 7 from the main text and figure E1 reported in the appendix
** To create figures 1, 2, 3 and 4 from the main text please use R scripts figure1_and_figure2.R, figure3.R and figure5.R

** Corresponding author: Mariyana Angelova - angelova@ceu.edu
** 15.01.2021 Vienna



clear all
set more off
** set working directory
cd "~/Desktop/Replication files"
use "./data.dta", clear



	
		
*** drop NAs in the alternation variables 
 drop if alt_rm_cp4y==. 
  	gen zero = 0
	gen zero10 = 9.5
	gen zero5 = 5
						

  ** Replication of analyses in the main Text
  
	**------------------------------
	** 
	** Analyses reported in Table 2
	**
	** Hierarchical Models
	**------------------------------
	
	**=========================================================
	** Model 1: 
	**=========================================================

	menbreg  nreforms c.alt_rm_cp4y c.alt_swsw_coalition_cp4y c.rm_distance_swswCoailtion n_cab_parties cab_av_realgdpgrChange  cab_av_unemp_crisis_d cab_av_inflationChange c.cab_duration_y  i.policy_f || country_f:, irr
	est sto m1
			
	**===============================================================
	** model 2: interaction between RM alternation and policing index
	**===============================================================

	menbreg  nreforms  c.alt_rm_cp4y##c.mv_index_value  c.alt_swsw_coalition_cp4y c.rm_distance_swswCoailtion n_cab_parties  cab_av_realgdpgrChange  cab_av_unemp_crisis_d cab_av_inflationChange c.cab_duration_y i.policy_f || country_f:, irr
	est sto m2


		**=========================================================
		** Figure 6
		**=========================================================

		margins, dydx(alt_rm_cp4y) at (mv_index_value=(-1.9(.03)1) ) post coeflegend level (95)
		marginsplot , ylabel (-2(2)15, angle(0) nogrid) xlabel (-2(1)1)   yline(0, lcolor(red)) ciopts(lcolor(black) lpattern(dash)) plotopts(lcolor(black) mcolor(black) recast(line) lwidth(thick) lpattern(solid))  graphregion(style(none) color(gs16)) plotregion(lcolor(black)) title ("Average Marginal Effect of RM Alternation"  ,   color(black) size(5) ) xtitle ("Legislative Policing Strength", size(5) height (5)) subtitle("Model 2",size(5))  ytitle("Number of Reform Measures",size(5) height(5) ) scale (0.9) ysize(2) xsize(1.9) name (fig6, replace) recastci(rline)
		graph save fig6 "./figure6.gph", replace

	
		**=========================================================
		** Figure E1 (Appendix), based on Model 2
		** Graphs with different hypothetical values of Policing Strength
		**=========================================================
			
		** policing strength - 2
		margins, at (alt_rm_cp4y=(0(0.03)3) mv_index_value=(-1.9)) 
		marginsplot,addplot(scatter zero alt_rm_cp4y if alt_rm_cp4y<=3 , mcolor(black%20) legend(off) ylabel(0(10)70 , nogrid) ) ylabel (0(10)70, angle(0) nogrid) xlabel (0(0.5)3)  ciopts(lcolor(black) lpattern(dash)) plotopts(lcolor(black) mcolor(black) recast(line) lwidth(thick) lpattern(solid))  graphregion(style(none) color(gs16)) plotregion(lcolor(black)) title ("Policing Strength = -1.9"  ,   color(black) size(5) height (5) ) xtitle ("Resp Minister Alternation", size(5) height (5)) subtitle("") ytitle("N of Reform Measures",size(5) height(5) ) scale (0.8) ysize(2) xsize(1.9) name (mv1a, replace) recastci(rline)

			
		** policing strength - 1
		margins, at (alt_rm_cp4y=(0(0.03)3) mv_index_value=(-1)) 
		marginsplot ,addplot(scatter zero alt_rm_cp4y if alt_rm_cp4y<=3, mcolor(black%20) legend(off) ylabel(0(10)70, nogrid) ) ylabel (0(10)70, angle(0) nogrid) xlabel (0(0.5)3)  ciopts(lcolor(black) lpattern(dash)) plotopts(lcolor(black) mcolor(black) recast(line) lwidth(thick) lpattern(solid))  graphregion(style(none) color(gs16)) plotregion(lcolor(black)) title ("Policing Strength = -1"  ,   color(black) size(5) height (5) ) xtitle ("Resp Minister Alternation", size(5) height (5)) subtitle("") ytitle("N of Reform Measures",size(5) height(5) ) scale (0.8) ysize(2) xsize(1.9) name (mv2a, replace) recastci(rline)

				
		** policing strength 0
		margins, at (alt_rm_cp4y=(0(0.03)3) mv_index_value=(0)) 
		marginsplot ,addplot(scatter zero alt_rm_cp4y if alt_rm_cp4y<=3, mcolor(black%20) legend(off) ylabel(0(10)70, nogrid) ) ylabel (0(10)70, angle(0) nogrid) xlabel (0(0.5)3)  ciopts(lcolor(black) lpattern(dash)) plotopts(lcolor(black) mcolor(black) recast(line) lwidth(thick) lpattern(solid))  graphregion(style(none) color(gs16)) plotregion(lcolor(black)) title ("Policing Strength = 0"  ,   color(black) size(5) height (5) ) xtitle ("Resp Minister Alternation", size(5) height (5)) subtitle("") ytitle("N of Reform Measures",size(5) height(5) ) scale (0.8) ysize(2) xsize(1.9) name (mv3a, replace) recastci(rline)

		** policing strength 1
		margins, at (alt_rm_cp4y=(0(0.03)3) mv_index_value=(1)) 	
		marginsplot ,addplot(scatter zero alt_rm_cp4y if alt_rm_cp4y<=3, mcolor(black%20) legend(off) ylabel(0(10)70, nogrid) ) ylabel (0(10)70, angle(0) nogrid) xlabel (0(0.5)3)  ciopts(lcolor(black) lpattern(dash)) plotopts(lcolor(black) mcolor(black) recast(line) lwidth(thick) lpattern(solid))  graphregion(style(none) color(gs16)) plotregion(lcolor(black)) title ("Policing Strength = 1"  ,   color(black) size(5) height (5) ) xtitle ("Resp Minister Alternation", size(5) height (5)) subtitle("") ytitle("N of Reform Measures",size(5) height(5) ) scale (0.8) ysize(2) xsize(1.9) name (mv4a, replace) recastci(rline)
		
		*graph combine mv1 mv2 mv3 mv4 , ysize(2) xsize(2)  graphregion(style(none) color(gs16))
		graph combine  mv1a mv2a mv3a mv4a   , cols(2) iscale (0.75)    graphregion(style(none) color(gs16) margin(zero))  ysize(2) xsize(2)
		graph save Graph "./figureE1.gph", replace

		
	
		
	**=================================================================================================================================================
	** model 3: interaction between seat weighted and saliency weighted coalition alternation and policing index
	**=================================================================================================================================================
	
	menbreg  nreforms  c.alt_rm_cp4y  c.alt_swsw_coalition_cp4y##c.mv_index_value n_cab_parties c.rm_distance_swswCoailtion   cab_av_realgdpgrChange  cab_av_unemp_crisis_d cab_av_inflationChange c.cab_duration_y i.policy_f || country_f:, irr 
		est sto m3
		
		margins, dydx(alt_swsw_coalition_cp4y) at (mv_index_value=(-1.9(.03)1) )  post coeflegend level (95)
		marginsplot , ylabel (-2(2)14, angle(0) nogrid) xlabel (-2(1)1)   yline(0, lcolor(red)) ciopts(lcolor(black) lpattern(dash)) plotopts(lcolor(black) mcolor(black) recast(line) lwidth(thick) lpattern(solid))  graphregion(style(none) color(gs16)) plotregion(lcolor(black)) title (""  ,   color(black) size(5) ) xtitle ("Legislative Policing Strength", size(5) height (5)) subtitle("",size(5))  ytitle("Number of Reform Measures",size(5) height(5) ) scale (0.9) ysize(2) xsize(1.9) name (fig7, replace) recastci(rline)
		graph save fig7 "./figure7.gph", replace

	
	**=========================================================
	** Create tables
	**=========================================================

	
	* Export table 1: descriptive statistics
	estpost tabstat nreforms alt_rm_cp4y  alt_swsw_coalition_cp4y mv_index_value  n_cab_parties rm_distance_swswCoailtion  cab_av_realgdpgrChange  cab_av_unemp_crisis_d cab_av_inflationChange cab_duration_y, s(mean sd min p25 p50 p75 max) c(s)
	esttab using res_table_1.rtf, replace cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2)) p25(fmt(2))  p50(fmt(2))  p75(fmt(2)) max(fmt(2))") label
	
	* Export table 2: regression results
	esttab m1 m2 m3   using res_table_2.rtf, label se b(2) scalar(ll aic) sfmt(0) nomtitles replace eform star(~ .1 * .05 ** .01 *** 0.001)
	
	**========================================================================================================
	** Plot figure 1 "Ministerial Autonomy vs. Policy-by-Policy Compromise" and figure 2 "Ministerial Drift"
	** To plot figure 1 and 2 use R script figure1_and_figure2.R
	**========================================================================================================
	
	**========================================================================================================
	** Plot figure 3 "Government Alterantion and Number of Important Reforms" 
	** To plot this figure 3 use R script figure3.R
	**========================================================================================================
	
	**========================================================================================================
	** Plot figure 4 "Number of Social and Economic Government Reforms Meausures Across Countries and Time
	** To plot figure 4: you need to load the dataset data_for_figure4__reforms_by_year.dta
	**========================================================================================================
	
	clear all
	set more off
	use "./data_for_figure4__reforms_by_year.dta", clear

		* install package dependencies (this automatically replaces old packages, so make sure to uncomment if this is unwanted!)
		ssc install devr2, replace
		ssc install estout, replace

		* set panel structure
		xtset country year	

		* graph of number of reform measures by policy area
		twoway area economy_plus_social social year if year >= 1985 & year <= 2005, by(country) ylabel(0(10)30) ytitle("Number of reform measures") 
		graph save Graph "./figure4.gph", replace




	** to replicate footnote 10 - run all above analyses with the following two changes
	** INSTEAD of alt_swsw_coalition_cp4y USE alt_swsw_coalition_cp
	** INSTEAD of alt_rm_cp4y USE alt_rm_cp

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
		
